Skip to content

Fix emoji and CJK cursor display width#117

Merged
ryanoneill merged 1 commit intomainfrom
fix/emoji-cursor-display-width
Mar 2, 2026
Merged

Fix emoji and CJK cursor display width#117
ryanoneill merged 1 commit intomainfrom
fix/emoji-cursor-display-width

Conversation

@ryanoneill
Copy link
Owner

Summary

  • Add cursor_display_position() to InputFieldState and TextAreaState that returns terminal column width using unicode-width, correctly handling wide characters (emoji, CJK) that occupy 2 terminal columns
  • Update all 6 cursor rendering sites (InputField, TextArea, Form, LogViewer, DataGrid, ChatView) to use display width instead of character count
  • Keeps existing cursor_position() API unchanged (175+ test call sites)

Before: Text "A😀B" with cursor after emoji — cursor_position() returns 2, cursor renders 1 column too far left
After: cursor_display_position() returns 3 (A=1col + 😀=2cols), cursor renders at correct position

Test plan

  • New unit tests for cursor_display_position() on both InputField and TextArea (ASCII, emoji, CJK, mixed, empty, multiline)
  • Doc tests on both new methods showing difference from cursor_position()
  • All existing tests pass (278 tests)
  • cargo clippy --all-targets --all-features -- -D warnings clean

🤖 Generated with Claude Code

@codecov-commenter
Copy link

codecov-commenter commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.64%. Comparing base (e096986) to head (0c74b85).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #117   +/-   ##
=======================================
  Coverage   92.64%   92.64%           
=======================================
  Files         100      100           
  Lines        9545     9550    +5     
=======================================
+ Hits         8843     8848    +5     
  Misses        702      702           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add cursor_display_position() to InputFieldState and TextAreaState that
returns terminal column width using unicode-width, accounting for wide
characters (emoji, CJK) that occupy 2 terminal columns. Update all 6
rendering sites to use display width instead of character count.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ryanoneill ryanoneill force-pushed the fix/emoji-cursor-display-width branch from d7ce4bb to 0c74b85 Compare March 2, 2026 16:45
@ryanoneill ryanoneill merged commit 44a4274 into main Mar 2, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants